clear all
set more off

global chemin "HERE indicated path to the main folder"
cd "$chemin\data"

use final_IHME22, clear
drop if recipient_name == "Unallocated/Unspecified"
* we drop 2019 and 2020 because we don't have bilateral data but just global data
drop if year >= 2019
gen MCP = 0
replace MCP = 1 if year <1993 /* actif jusqu'en 12/1992 inclus */
replace MCP = 1 if year == 1995
replace MCP = 1 if year >1999 & year <2009 /* actif en 1999/2000 et à partir du 01/2001 jusqu'en 12/2008*/
replace MCP = 1 if year >2016 /*actif 01/2017 - 12/2020*/ 


* Intsrument construction
	* Part 1 : probability of receiving FP aid when MCP is not active
	gen aid_pc = (rmh_fp_dah_20_US >0)
	bys recipient_name : egen aid = mean(aid_pc) if MCP == 0
	bys recipient_name : egen FPr = mean(aid)

* instrument 1 : Probability of receiving FP aid when MCP is not active * share channelled through NGO during OBAMA term * policy
	gen instrument1 = FPr * share_NGOUS_Obama * MCP
* instrument 2 : Probability of receiving FP aid when MCP is not active * share channelled through NGO when MCP not active * policy
	gen instrument2 = FPr * share_NGOUS_MCP * MCP

* Creation of controls
	gen lngdppc = ln(GDPpc_r)
	gen lnpopr = ln(pop_r)
	gen laidfp = ln(rmh_fp_dah_20 + ((rmh_fp_dah_20^2 +1)^0.5))
	gen laidUS = ln(rmh_fp_dah_20_US + ((rmh_fp_dah_20_US^2 +1)^0.5))

	gen laidfp2 = ln(rmh_fp_dah_20 + 1)
	gen laidUS2 = ln(rmh_fp_dah_20_US + 1)

	egen id_o = group(donor)
	egen id_dr = group(donor recipient_name)
	egen id_r = group( recipient_name)
	gen fert2 = fertility_r *fertility_r

	sum FPr if year == 2000 & donor == "France", de
	gen high = (FPr >r(p50) )
	replace high = . if FPr == . 

	sum share_NGOUS_Obama if year == 2000 & donor == "France", de
	gen highNGO = (share_NGOUS_Obama >r(p50)  )
	replace highN = 0 if  share_NGOUS_Obama == .

xtset id_dr year
global controls  lngdppc lnpopr poverty_r
global controls1 lngdppc lnpopr poverty_r life_expectencyfe_r incidenceHIV_r HIV1549_r fert2 fertility_r adofertility_r maternalmortality_r
global controls2 lngdppc lnpopr poverty_r life_expectencyfe_r incidenceHIV_r HIV1549_r fert2 fertility_r adofertility_r maternalmortality_r polity2
global controls3 lngdppc lnpopr poverty_r life_expectencyfe_r incidenceHIV_r HIV1549_r fert2 fertility_r adofertility_r maternalmortality_r polity2 UN_dr 

* controls interacted with FPr*ShareNGOr
foreach i of varlist $controls3 {
	gen `i'_int = `i' * FPr * share_NGOUS_Obama
}


* Défeinition of different set of controls 
global controlsi  L.lngdppc* L.lnpopr* L.poverty_r*    																				
global controls1i L.lngdppc* L.lnpopr* L.poverty_r* L.life_expectencyfe_r* L.HIV1549_r* L.incidenceHIV_r* L.fert2* L.fertility* L.adofertility* L.maternalmortality_r*
global controls2i L.lngdppc* L.lnpopr* L.poverty_r* L.life_expectencyfe_r* L.HIV1549_r* L.incidenceHIV_r* L.fert2* L.fertility* L.adofertility* L.maternalmortality_r* L.polity2* 
* will exclude the EU and the BMGF because no data on UN vote...
global controls3i L.lngdppc* L.lnpopr* L.poverty_r* L.life_expectencyfe_r* L.HIV1549_r* L.incidenceHIV_r* L.fert2* L.fertility* L.adofertility* L.maternalmortality_r* L.polity2* L.UN_dr* 


label variable laidUS "Log of US FP aid\$_{rt-1}$"
label variable instrument1 "MCP\$_{t}$ * FP\$_{r}$ * shareONG\$_{r}$"

/* Baseline results*/
ivreghdfe laidfp $controls2i (L2.laidUS=L2.instrument1),  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor) first
est store Baseline
gen in_sample4 =e(sample)




preserve
keep year recipient_name rmh_fp_dah_20_US  aid_pc MCP rmh_dah_20_US   rmh_fp_dah_20
duplicates drop *, force
collapse (sum) rmh_fp_dah_20_US rmh_dah_20_US  , by(year )
sum rmh_dah_20_US
		gen max = r(max)
twoway area max year   if inrange(year, 1990, 1993),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1994, 1995),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1999, 2008),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 2017, 2020),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| line rmh_fp_dah_20_US  year ,   ytitle("Thousand of constant 2020 US dollars", axis(1)) ylabel(,labsize(vsmall ) format(%12.0fc) axis(1))  ///
		scheme(s2manual) graphregion( color(white)) xtitle("") ///
		|| line rmh_dah_20_US  year ,   yaxis(2) ytitle(" ", axis(2)) lstyle(p1 ) ylabel(,labsize(vsmall ) format(%12.0fc) axis(2))  ///
		legend(order( 5 "Family Planning" 6 "Repr. & Maternal Health")  size(medium) cols(2)) ///
		ytitle("Thousand of constant 2020 US dollars") lstyle(p1 ) ylabel(,labsize(small )  format(%12.0fc)) xlabel(1990(4)2018)
		graph export "..\output\aidIHME.eps", as(eps) preview(on) replace
restore


/* stat desc raw data */
preserve
use "input\IHME_DAH_DATABASE_1990_2020_Y2021M09D22.dta", clear
drop if elim_ch == 1
drop elim_ch
drop if recipient_c == "Administrative expenses"
drop if recipient_c == "NA"
drop if recipient_c == "Global"
drop if source == "Corporate_donations"
drop if source == "Debt_repayments"
drop if source == "Non_OECD_DAC_countries"
drop if source == "Other_OECD_DAC_countries"
drop if source == "Other"
drop if source == "Private_other"
drop if source == "Unallocable"
gen USA =  (source == "United_States")
keep year  rmh_fp_dah_20  rmh_dah_20 USA source
destring rmh_fp_dah_20 rmh_dah_20, replace force

collapse (sum) rmh_fp_dah_20 rmh_dah_20  , by(year USA)
sum rmh_fp_dah_20
		gen max = r(max)
twoway area max year   if inrange(year, 1990, 1993),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1994, 1995),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1999, 2008),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 2017, 2020),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| line rmh_fp_dah_20  year if USA == 1 ///
		|| line rmh_fp_dah_20  year if USA == 0,    ///
		scheme(s2manual) graphregion( color(white)) xtitle("") ///
		legend(order( 5 "US FP aid" 6 "Other donors' FP aid") cols(2)) ///
		ytitle("Thousand of constant 2020 US dollars") lstyle(p1 ) ylabel(,labsize(small )  format(%12.0fc)) xlabel(1990(4)2018)
		graph export "..\output\aidIHMEraw_compa.eps", as(eps) preview(on) replace
restore

preserve
use "input\IHME_DAH_DATABASE_1990_2020_Y2021M09D22.dta", clear
drop if elim_ch == 1
drop elim_ch
drop if recipient_c == "Administrative expenses"
drop if recipient_c == "NA"
drop if recipient_c == "Global"
gen USA =  (source == "United_States")
keep year  rmh_fp_dah_20  rmh_dah_20 USA
destring rmh_fp_dah_20 rmh_dah_20, replace force

collapse (sum) rmh_fp_dah_20 rmh_dah_20  , by(year USA)
sum rmh_dah_20
		gen max = r(max)
twoway area max year   if inrange(year, 1990, 1993),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1994, 1995),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1999, 2008),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 2017, 2020),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| line rmh_dah_20  year if USA == 1 ///
		|| line rmh_dah_20  year if USA == 0,   ///
		scheme(s2manual) graphregion( color(white)) xtitle("") ///
		legend(order( 5 "US RMH aid" 6 "Other donors' RMH aid '") cols(2)) ///
		ytitle("Thousand of constant 2020 US dollars") lstyle(p1 ) ylabel(,labsize(small )  format(%12.0fc)) xlabel(1990(4)2018)
		graph export "..\output\aidIHMEraw_compaRMH.eps", as(eps) preview(on) replace
restore


preserve
use "input\IHME_DAH_DATABASE_1990_2020_Y2021M09D22.dta", clear
drop if elim_ch == 1
drop if recipient_c == "Administrative expenses"
drop if recipient_c == "NA"
drop if recipient_c == "Global"
*drop if recipient_c == "Unallocated/Unspecified"
*drop if year >2018
drop elim_ch
drop if source == "United_States"
keep year  rmh_fp_dah_20  rmh_dah_20
destring rmh_fp_dah_20 rmh_dah_20, replace force

collapse (sum) rmh_fp_dah_20 rmh_dah_20  , by(year )
sum rmh_fp_dah_20
		gen max = r(max)
twoway area max year   if inrange(year, 1990, 1993),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1994, 1995),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1999, 2008),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 2017, 2020),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| line rmh_fp_dah_20   year,     ///
		scheme(s2manual) graphregion( color(white)) xtitle("") ///
		legend(off) ///
		ytitle("Thousand of constant 2020 US dollars") lstyle(p1 ) ylabel(,labsize(small )  format(%12.0fc)) xlabel(1990(4)2018)
		graph export "..\output\aidIHMEother.eps", as(eps) preview(on) replace
restore



**# Bookmark #1 à reprendre avec les bonnes données

preserve 
use CRS, clear
keep if donorname == "United States"
keep if sectorcode == 130
bys year : egen total = sum(usd_c)
replace total = total * 1000
replace usd_c = usd_c * 1000
keep if purposecod == 13030
collapse (sum) usd_commitment_defl (mean) total, by(year )
sum total
gen max = r(max)
twoway area max year   if inrange(year, 1990, 1993),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1994, 1995),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1999, 2008),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 2017, 2020),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| line   total  year ,  ytitle("Thousand of constant 2020 US dollars", axis(1)) ylabel(,labsize(vsmall ) format(%12.0fc) axis(1)) xline(2017) ///
		|| line usd   year ,  yaxis(2) ytitle(" ", axis(2)) lstyle(p1 ) ylabel(,labsize(vsmall ) format(%12.0fc) axis(2))  ///
		scheme(s2manual) graphregion( color(white)) xtitle("") 		///
		legend(order( 4 "Pop. Pol. & Reproductive Health" 5 "Family planning") cols(2)) 
		graph export "..\output\aidOECD.eps", as(eps) preview(on) replace
restore

preserve 
use CRS, clear
keep if donorname == "United States"
keep if sectorcode == 130
bys year : egen total = sum(usd_disbursement_defl)
replace total = total * 1000
replace usd_c = usd_disbursement_defl * 1000
keep if purposecod ==  13030
collapse (sum) usd_disbursement_defl (mean) total, by(year )
sum total
gen max = r(max)
twoway area max year   if inrange(year, 1990, 1993),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1994, 1995),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1999, 2008),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 2017, 2020),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| line   total  year ,  ytitle("Thousand of constant 2020 US dollars", axis(1)) ylabel(,labsize(vsmall ) format(%12.0fc) axis(1)) xline(2017) ///
		|| line usd   year ,  yaxis(2) ytitle(" ", axis(2)) lstyle(p1 ) ylabel(,labsize(vsmall ) format(%12.0fc) axis(2))  ///
		scheme(s2manual) graphregion( color(white)) xtitle("") 		///
		legend(order( 4 "Pop. Pol. & Reproductive Health" 5 "Family planning") cols(2)) 
		graph export "..\output\aidOECDd.eps", as(eps) preview(on) replace
restore

preserve 
use CRS.dta, clear
replace donorname = "a" if donorname != "United States"
replace usd_c = usd_c * 1000
keep if purposecod == 13030
collapse (sum) usd_commitment_defl , by(year donorname )
sum usd
gen max = r(max)
twoway area max year   if inrange(year, 1990, 1993),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1994, 1995),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1999, 2008),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 2017, 2020),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
			|| line usd   year if donorname == "a",    ///
			|| line usd   year if donorname != "a", lstyle(p1 )   ///
		scheme(s2manual) graphregion( color(white)) xtitle("FP aid") 		///
		legend(order( 4 "Other donors" 5 "US") cols(2)) 
		graph export "..\output\aidOECDother.eps", as(eps) preview(on) replace
restore




**# Bookmark #2

preserve
keep year recipient_name rmh_fp_dah_20_US  high* aid_pc MCP rmh_dah_20_US in_sa  
duplicates drop *, force
collapse (sum) rmh_fp_dah_20_US, by(year high)
*drop if year <1993
sum rmh_fp_dah_20_US
gen max = r(max)
twoway area max year   if inrange(year, 1990, 1993),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1994, 1995),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1999, 2008),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 2017, 2020),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| line rmh_fp_dah_20_US   year if high == 1, yaxis(1)  ytitle("Thousand of constant 2020 US dollars", axis(1)) ylabel(,labsize(small ) axis(1)) xline(2017) ///
		|| line rmh_fp_dah_20_US   year if high == 0, yaxis(2) ytitle(" ", axis(2)) lstyle(p1 ) ylabel(,labsize(small ) axis(2))   ///
		scheme(s2manual) graphregion( color(white)) xtitle("") lstyle(p1 p3 ) ///
		legend(order( 5 "High exposure (left axis)" 6 "Low exposure (right axis)") cols(2)) ///
		xlabel(1990(4)2018)
		graph export "..\output\highlow.eps", as(eps) preview(on) replace
restore


preserve
gen u = FPr*share_NGOUS_Obama 
keep year recipient_name rmh_fp_dah_20_US FPr share_NGOUS_Obama high* aid_pc MCP rmh_dah_20_US in_sa  u
duplicates drop *, force
sum u, det
gen hh = (u > r(p50))
tab hh
collapse (sum) rmh_fp_dah_20_US, by(year hh)
*drop if year <1993
sum rmh_fp_dah_20_US
gen max = r(max)
twoway area max year   if inrange(year, 1990, 1993),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1994, 1995),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1999, 2008),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 2017, 2020),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| line rmh_fp_dah_20_US   year if hh == 1, yaxis(1)  ytitle("Thousand of constant 2020 US dollars", axis(1)) ylabel(,labsize(small ) axis(1)) xline(2017) ///
		|| line rmh_fp_dah_20_US   year if hh == 0, yaxis(2) ytitle(" ", axis(2)) lstyle(p1 ) ylabel(,labsize(small ) axis(2))   ///
		scheme(s2manual) graphregion( color(white)) xtitle("") lstyle(p1 p3 ) ///
		legend(order( 5 "High exposure (left axis)" 6 "Low exposure (right axis)") cols(2)) ///
		xlabel(1990(4)2018)
		graph export "..\output\hh.eps", as(eps) preview(on) replace
restore

preserve
gen u = FPr * share_NGOUS_Obama
sum u, det
gen hh = (u >=r(p50))
tab hh
collapse (sum) rmh_fp_dah_20, by(year hh)
*drop if year <1993
sum rmh_fp_dah_20
gen max = r(max)
twoway area max year   if inrange(year, 1990, 1993),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1994, 1995),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1999, 2008),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 2017, 2020),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| line rmh_fp_dah_20   year if hh == 1,  ytitle("Thousand of constant 2020 US dollars", axis(1)) ylabel(,labsize(small ) axis(1)) xline(2017) ///
		|| line rmh_fp_dah_20   year if h == 0,  ///
		scheme(s2manual) graphregion( color(white)) xtitle("") lstyle(p1 p3 ) ///
		legend(order( 5 "High exposure" 6 "Low exposure") cols(2)) ///
		 xlabel(1993(7)2020)
		graph export "..\output\hhother.eps", as(eps) preview(on) replace
restore

preserve
collapse (sum) rmh_fp_dah_20, by(year high)
*drop if year <1993
sum rmh_fp_dah_20
gen max = r(max)
twoway area max year   if inrange(year, 1990, 1993),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1994, 1995),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1999, 2008),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 2017, 2020),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| line rmh_fp_dah_20   year if high == 1, yaxis(1)  ytitle("Thousand of constant 2020 US dollars", axis(1)) ylabel(,labsize(small ) axis(1)) xline(2017) ///
		|| line rmh_fp_dah_20   year if high == 0, yaxis(2) ytitle(" ", axis(2)) lstyle(p1 ) ylabel(,labsize(small ) axis(2))   ///
		scheme(s2manual) graphregion( color(white)) xtitle("") lstyle(p1 p3 ) ///
		legend(order( 5 "High exposure (left)" 6 "Low exposure (right)") cols(2)) ///
		 xlabel(1990(4)2018)
		graph export "..\output\highlowother.eps", as(eps) preview(on) replace
restore


preserve
keep year recipient_name rmh_fp_dah_20_US FPr  high* aid_pc MCP rmh_dah_20_US in_sa  
duplicates drop *, force
collapse (sum) rmh_fp_dah_20_US, by(year highN)
*drop if year <1993
sum rmh_fp_dah_20_US
gen max = r(max)
twoway area max year   if inrange(year, 1990, 1993),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1994, 1995),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1999, 2008),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 2017, 2020),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| line rmh_fp_dah_20_US   year if high == 1, yaxis(1)  ytitle("Thousand of constant 2020 US dollars") ylabel(,labsize(small ) axis(1)) xline(2017) ///
		|| line rmh_fp_dah_20_US   year if high == 0, yaxis(2)  ytitle(" ", axis(2))  ///
		scheme(s2manual) graphregion( color(white)) xtitle("") lstyle(p1 p3 ) ///
		legend(order( 5 "NGO high exposure" 6 "NGO low exposure") cols(2)) ///
		 xlabel(1990(4)2018)
		graph export "..\output\highlowNGO.eps", as(eps) preview(on) replace
restore


preserve
collapse (sum) rmh_fp_dah_20, by(year highN)
*drop if year <1993
tab year
sum rmh_fp_dah_20
gen max = r(max)
twoway  area max year   if inrange(year, 1990, 1993),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1994, 1995),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1999, 2008),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 2017, 2020),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| line rmh_fp_dah_20   year if high == 1, yaxis(1)  ytitle("Thousand of constant 2020 US dollars", axis(1)) ylabel(,labsize(small ) axis(1)) xline(2017) ///
		|| line rmh_fp_dah_20   year if high == 0, yaxis(2) ytitle(" ", axis(2)) lstyle(p1 ) ylabel(,labsize(small ) axis(2))   ///
		scheme(s2manual) graphregion( color(white)) xtitle("") lstyle(p1 p3 ) ///
		legend(order( 5 "NGO high exposure (left)" 6 "NGO low exposure (right)") cols(2)) ///
		 xlabel(1990(4)2018)
		graph export "..\output\highlowNGOother.eps", as(eps) preview(on) replace
restore

**# Bookmark #3

preserve
use CRS, clear
keep if donorname == "United States" 
replace usd_commitment_defl = usd_commitment_defl * 1000
replace usd_disbursement_defl = usd_disbursement_defl * 1000
bys recipientname : replace recipientna = "States Ex-Yugoslavia" if recipientn == "States Ex-Yugoslavia unspecified"
expand 2 if recipientname == "North Macedonia"
bys recipientname year : replace recipientna = "Former Yugoslav Republic of Macedonia" if recipientn == "North Macedonia" & _n  == 1
replace recipientname = "Eswatini" if recipientname =="Swaziland"
drop if strpos(recipientn,"regional")>0
drop if strpos(recipientn,"unspecified")>0
do ..\do-file\nettoyage_base
replace purposecode = 1 if purposecode != 13030

collapse (sum) usd_disbursement_defl usd_commitment_defl, by(year purposecode)
bys year : egen total = total(usd_disbursement_defl)
gen share = usd_disbursement_defl / total
replace share = share * 100
sum share if purpose == 13030
gen max = r(max)


twoway area max year   if inrange(year, 1990, 1993),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1994, 1995),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1999, 2008),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 2017, 2020),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| line   share  year if purpose == 13030,  ytitle("% of FP US aid on total US aid") ///
		scheme(s2manual) graphregion( color(white)) xtitle("") 	legend(off) ///
		 xlabel(2000(5)2020)	
		graph export "..\output\aidOECDshared.eps", as(eps) preview(on) replace
restore

preserve
use CRS, clear
keep if donorname == "United States" 
replace usd_commitment_defl = usd_commitment_defl * 1000
replace usd_disbursement_defl = usd_disbursement_defl * 1000
bys recipientname : replace recipientna = "States Ex-Yugoslavia" if recipientn == "States Ex-Yugoslavia unspecified"
expand 2 if recipientname == "North Macedonia"
bys recipientname year : replace recipientna = "Former Yugoslav Republic of Macedonia" if recipientn == "North Macedonia" & _n  == 1
replace recipientname = "Eswatini" if recipientname =="Swaziland"
drop if strpos(recipientn,"regional")>0
drop if strpos(recipientn,"unspecified")>0
replace purposecode = 1 if purposecode != 13030

collapse (sum) usd_disbursement_defl usd_commitment_defl, by(year purposecode)
bys year : egen total = total(usd_commitment_defl)
gen share = usd_commitment_defl / total
replace share = share * 100
sum share if purpose == 13030
gen max = r(max)


twoway area max year   if inrange(year, 1990, 1993),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1994, 1995),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 1999, 2008),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| area max year   if inrange(year, 2017, 2020),   ///
		lcolor(bg) fcolor(gray)  fintensity(inten20) /// 
		|| line   share  year if purpose == 13030,  ytitle("% of FP US aid on total US aid") ///
		scheme(s2manual) graphregion( color(white)) xtitle("") 	legend(off) ///
		 xlabel(2000(5)2020)	
		graph export "..\output\aidOECDsharec.eps", as(eps) preview(on) replace
restore

use placebo_barret1, clear
sum data_store_LlaidUS, det
local p5 = r(p5)
local p95 = r(p95)
local p10 = r(p10)
local p90 = r(p90)
local mean = r(mean)
local median = r(p50)
local p1 = r(p1)
local p99 = r(p99)
di `mean' 
di `p5'
di  `p95' 
di `p99'
preserve
*keep if data_store_LlaidUS >`p1'
*keep if data_store_LlaidUS <`p99'
kdensity data_store_LlaidUS, gen(x fx) nograph

sum fx x
twoway line fx x ///
	|| area fx x if x < `p10', color(gs15) ||  area fx x if x <`p5', color(gs10)  ///
	|| area fx x if x > `p90', color(gs15) ||  area fx x if x > `p95', color(gs10)  	///
	xline(`mean', lpattern(dot)) xline(`median', lpattern(-)) xline(0.03) ///
	scheme(s2manual) graphregion( color(white))  ///
	xtitle("2SLS coefficient from Barrett & Christian (2021)")   ///
		ytitle("Density")  ylabel(,labsize(small )  format(%12.1fc)) legend(off) ///
		text(1 0.065 "Median", orientation(vertical) size(vsmall)) ///
		text(3 0.065 "Mean", orientation(vertical) size(vsmall)) ///
		text(2 0.03 "Baseline", orientation(vertical) size(vsmall)) ///
		xlabel(0(0.05)0.15)
		
	*	///
	*	text(0.1 -0.5 "Mean", orientation(vertical)) */
	restore	

		
graph export "..\output\barretthist1.eps", as(eps) preview(on) replace


use placebo_barret2, clear

sum data_store_LlaidUS, det
local p5 = r(p5)
local p95 = r(p95)
local p10 = r(p10)
local p90 = r(p90)
local mean = r(mean)
local median = r(p50)
local p1 = r(p1)
local p99 = r(p99)
di `mean' 
di `p5'
di  `p95' 
di `p99'
preserve
*keep if data_store_LlaidUS >`p1'
*keep if data_store_LlaidUS <`p99'
kdensity data_store_LlaidUS, gen(x fx) nograph

sum fx x
twoway line fx x ///
	|| area fx x if x < `p10', color(gs15) ||  area fx x if x <`p5', color(gs10)  ///
	|| area fx x if x > `p90', color(gs15) ||  area fx x if x > `p95', color(gs10)  	///
	xline(`mean', lpattern(dot)) xline(`median', lpattern(-)) xline(0.086) ///
	scheme(s2manual) graphregion( color(white))  ///
	xtitle("2SLS coefficient from Barrett & Christian (2021)")   ///
		ytitle("Density")  ylabel(,labsize(small )  format(%12.1fc)) legend(off) ///
		text(1 0.108 "Median", orientation(vertical) size(vsmall)) ///
		text(3 0.113 "Mean", orientation(vertical) size(vsmall)) ///
		text(2 0.084 "Baseline", orientation(vertical) size(vsmall)) ///
		xlabel(0.04(0.05)0.14)
		
	*	///
	*	text(0.1 -0.5 "Mean", orientation(vertical)) */
	restore	

		
graph export "..\output\barretthist2.eps", as(eps) preview(on) replace


use placebo_barret3, clear
sum data_store_LlaidUS, det
local p5 = r(p5)
local p95 = r(p95)
local p10 = r(p10)
local p90 = r(p90)
local mean = r(mean)
local median = r(p50)
local p1 = r(p1)
local p99 = r(p99)
di `mean' 
di `p5'
di  `p95' 
di `p99'
preserve
*keep if data_store_LlaidUS >`p1'
*keep if data_store_LlaidUS <`p99'
kdensity data_store_LlaidUS, gen(x fx) nograph

sum fx x
twoway line fx x ///
	|| area fx x if x < `p10', color(gs15) ||  area fx x if x <`p5', color(gs10)  ///
	|| area fx x if x > `p90', color(gs15) ||  area fx x if x > `p95', color(gs10)  	///
	xline(`mean', lpattern(dot)) xline(`median', lpattern(-)) xline(0.10) ///
	scheme(s2manual) graphregion( color(white))  ///
	xtitle("2SLS coefficient from Barrett & Christian (2021)")   ///
		ytitle("Density")  ylabel(,labsize(small )  format(%12.1fc)) legend(off) ///
		text(1 0.14 "Median", orientation(vertical) size(vsmall)) ///
		text(3 0.14 "Mean", orientation(vertical) size(vsmall)) ///
		text(2 0.10 "Baseline", orientation(vertical) size(vsmall)) ///
		xlabel(0.05(0.05)0.20)
		
	*	///
	*	text(0.1 -0.5 "Mean", orientation(vertical)) */
	restore	

		
graph export "..\output\barretthist3.eps", as(eps) preview(on) replace

use placebo_barret, clear
sum data_store_LlaidUS, det
local p5 = r(p5)
local p95 = r(p95)
local p10 = r(p10)
local p90 = r(p90)
local mean = r(mean)
local median = r(p50)
local p1 = r(p1)
local p99 = r(p99)
di `mean' 
di `p5'
di  `p95' 
di `p99'
preserve
*keep if data_store_LlaidUS >`p1'
*keep if data_store_LlaidUS <`p99'
kdensity data_store_LlaidUS, gen(x fx) nograph

sum fx x
twoway line fx x ///
	|| area fx x if x < `p10', color(gs15) ||  area fx x if x <`p5', color(gs10)  ///
	|| area fx x if x > `p90', color(gs15) ||  area fx x if x > `p95', color(gs10)  	///
	xline(`mean', lpattern(dot)) xline(`median', lpattern(-)) xline(0.006) ///
	scheme(s2manual) graphregion( color(white))  ///
	xtitle("2SLS coefficient from Barrett & Christian (2021)")   ///
		ytitle("Density")  ylabel(,labsize(small )  format(%12.1fc)) legend(off) ///
		text(1 0.02 "Median", orientation(vertical) size(vsmall)) ///
		text(3 0.02 "Mean", orientation(vertical) size(vsmall)) ///
		text(2 0.006 "Baseline", orientation(vertical) size(vsmall)) ///
		xlabel(-0.005(0.025)0.05)
		
	*	///
	*	text(0.1 -0.5 "Mean", orientation(vertical)) */
	restore	

		
graph export "..\output\barretthist0.eps", as(eps) preview(on) replace
